package kr.hikt.androidcomplete01.ch06;

import kr.hikt.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

public class SetParameterEx extends Activity {
	Button mLeftBtn;
	Button mRightBtn;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch06_setparameterex);
		
		mLeftBtn = (Button)findViewById(R.id.btnleft);
		mRightBtn = (Button)findViewById(R.id.btnright);
		
		
//		mLeftBtn.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				setParam(3, 1);
//			}
//		});
//		
//		mRightBtn.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				setParam(1, 3);
//			}
//		});
	}
	
	public void mOnClick(View v) {
		switch(v.getId()){
		case R.id.btnleft:
			setParam(3, 1);
			break;
		case R.id.btnright:
			setParam(1, 3);
			break;
		}
	}
	
//	View.OnClickListener listener = new OnClickListener() {
//		
//		@Override
//		public void onClick(View v) {
//			switch(v.getId()){
//			case R.id.btnleft:
//				setParam(3, 1);
//				break;
//			case R.id.btnright:
//				setParam(1, 3);
//				break;
//			}
//		}
//	};
	
	private void setParam(int left, int right){
		LinearLayout.LayoutParams lparam = (LinearLayout.LayoutParams)mLeftBtn.getLayoutParams();
		lparam.weight = left;
		mLeftBtn.setLayoutParams(lparam);
		
		LinearLayout.LayoutParams rparam = (LinearLayout.LayoutParams)mRightBtn.getLayoutParams();
		rparam.weight = right;
		mRightBtn.setLayoutParams(rparam);
	}
}
